/**
 * Copyright(c) 2010 Ceno Techonologies Co., Ltd.
 *
 * History:
 *   15-6-5 下午3:53 Created by lyyang
 */
package com.jade.bss.business.coupon.impl;

import java.util.List;
import javax.ejb.TransactionAttribute;
import javax.inject.Inject;
import javax.inject.Named;

import com.jade.bss.business.coupon.CouponDao;
import com.jade.bss.business.coupon.CouponInfo;
import com.jade.bss.business.coupon.CouponManager;
import com.jade.framework.base.criterion.Criteria;
import com.jade.framework.base.util.PagingList;
import org.springframework.transaction.annotation.Transactional;

/**
 * 卡券管理器实现
 *
 * @author <a href="mailto:lyyang@ceno.cn">lyyang</a>
 * @version 1.0 15-6-5 下午3:53
 */
@Named ("bss_couponManager")
public class CouponManagerImpl
        implements CouponManager
{
    private CouponDao couponDao;

    @Inject
    public void setCouponDao(@Named ("bss_couponDao") CouponDao couponDao)
    {
        this.couponDao = couponDao;
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Throwable.class)
    public CouponInfo add(CouponInfo base)
    {
        return couponDao.add(base);
    }

    public CouponInfo get(long id)
    {
        return couponDao.get(id);
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Throwable.class)
    public void update(CouponInfo base)
    {
        couponDao.update(base);
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Throwable.class)
    public void remove(CouponInfo base)
    {
        couponDao.remove(base);
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Throwable.class)
    public void remove(long[] ids)
    {
        for (long id : ids) {
            CouponInfo couponInfo = couponDao.get(id);
            if (couponInfo != null) {
                couponDao.remove(couponInfo);
            }
        }
    }

    @TransactionAttribute
    @Transactional (rollbackFor = Throwable.class)
    public void increaseQuantity(String cardId, long quantity)
            throws Exception
    {
        couponDao.increaseQuantity(cardId, quantity);
    }

    public CouponInfo get(String cardId)
    {
        return couponDao.get(cardId);
    }

    public CouponInfo getByFid(String fid)
    {
        return couponDao.getByFid(fid);
    }

    public PagingList<CouponInfo> query(Criteria criteria)
    {
        return couponDao.query(criteria);
    }

    public List<CouponInfo> list(Criteria criteria)
    {
        return couponDao.list(criteria);
    }
}
